package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    // http://127.0.0.1:8500/api/search/albumInfo 首页搜索
    @Operation(summary = "首页搜索")
    @PostMapping()
    public Result searchAlbums(@RequestBody AlbumIndexQuery query) {
        AlbumSearchResponseVo albumSearchResponseVo = searchService.searchAlbums(query);
        return Result.ok(albumSearchResponseVo);
    }

    // GET: http://127.0.0.1:8500/api/search/albumInfo/channel/2
    // 根据一级分类id查询三级分类列表数据
    @Operation(summary = "根据一级分类id查询三级分类列表数据")
    @GetMapping("channel/{c1Id}")
    public Result getAlbumInfoListByC1Id(@PathVariable("c1Id") Long c1Id) {
        List<Map> list = searchService.getChannel(c1Id);
        return Result.ok(list);
    }
    // 首页搜索推荐
    //  http://127.0.0.1:8500/api/search/albumInfo/completeSuggest/%E5%B0%8F
    @Operation(summary = "首页搜索推荐")
    @GetMapping("completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable("keyword") String keyword) {
        List<String> list =  searchService.completeSuggest(keyword);
        return Result.ok(list);
    }

    // 根据id查询专辑详情
    // http://127.0.0.1:8500/api/search/albumInfo/1633
    @Operation(summary = "根据id查询专辑详情")
    @GetMapping("{albumId}")
    public Result getAlbumInfoById(@PathVariable("albumId") Long albumId) {
        Map map = searchService.getAlbumInfoById(albumId);
        return Result.ok(map);
    }
    // 查询专辑的排行信息 参数为1级分类 id 和 统计信息
    // commentStatNum	buyStatNum	subscribeStatNumplayStatNum RhotScore
    // 查询一级分类下单专辑列表按照指定的方式排序 AlbumInfoIndexVo
    // http://127.0.0.1:8500/api/search/albumInfo/findRankingList/1/order
    @Operation(summary = "查询专辑的排行信息")
    @GetMapping("findRankingList/{c1Id}/{sort}")
    public Result findRankingList(@PathVariable("c1Id") Long c1Id,
                                  @PathVariable("sort") String sort) {
        List<AlbumInfoIndexVo> list = searchService.findRankingList(c1Id, sort);
        return Result.ok(list);
    }
    // 预热专辑的排行数据
    @Operation(summary = "预热专辑的排行数据")
    @GetMapping("updateLatelyAlbumRanking")
    public Result preheatRankingList() {
       searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }

}

